package timing.ukulele.portal.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import timing.ukulele.portal.mapper.SysDictMapper;
import timing.ukulele.portal.persistent.SysDict;

@Service
public class SysDictService extends BaseOperatorService<SysDictMapper, SysDict> {
    public IPage<SysDict> getPage(Long indexId, String value, String label, String remark, Boolean deleted, int current, int size) {
        Page<SysDict> page = new Page<>(current, size);
        LambdaQueryChainWrapper<SysDict> query = this.lambdaQuery();
        query.eq(SysDict::getIndexId, indexId);
        query.like(StringUtils.hasText(value), SysDict::getValue, value);
        query.like(StringUtils.hasText(label), SysDict::getLabel, label);
        query.like(StringUtils.hasText(remark), SysDict::getRemark, remark);
        if (deleted != null)
            query.eq(SysDict::getDeleted, deleted);
        query.orderByAsc(SysDict::getSort);
        IPage<SysDict> iPage = query.page(page);
        return page.setRecords(iPage.getRecords());
    }
}
